// pages/carts/carts.js
const http = require("../../models/http")
Page({
  data: {
    value:[]
  },
  onLoad: function (options) {
    http({
      url:"http://192.168.4.18:8000/cart",
      success:res=>{
        this.setData({
          value:res.data
        })
        console.log(this.data.value);
      }
    })
  },

  // 点击计步器，从而操作数组的productCover
  onStepper(event){
    console.log(event);
    this.data.value.forEach(res=>{
      if(res.id==event.currentTarget.dataset.id){
        res.productCount = event.detail
      }
    })
    this.setData({
      value:this.data.value
    })
  },

  // 复选框的value
  onChange(event){
    this.data.value.forEach(res=>{
      if(res.id==event.currentTarget.dataset.id){
        res.isSelected = event.detail
      }
    })
    this.setData({
      value:this.data.value
    })
  },

  // 选中复选框的时候让每个元素的isSelected改变
  onSum(event){
    this.data.value.forEach(res=>{
        res.isSelected = event.detail
    })
    this.setData({
      value:this.data.value
    })
  }
})